package com.seadragon.app.ksr.dao.jpa;

import java.util.List;

import javax.persistence.Query;

import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.seadragon.app.ksr.dao.GeocodedAddressDao;
import com.seadragon.app.ksr.model.GeocodedAddress;

@Repository("geocodedAddressDao")
@Transactional
public class GeocodedAddressDaoJpaImpl extends AbstractJpaDao implements GeocodedAddressDao {

	@SuppressWarnings("unchecked")
	@Override
	public List<GeocodedAddress> geocode(String address) {
		Query q = entityManager.createNamedQuery("geocode").setParameter("addressString", address);
		q.setHint("org.hibernate.readOnly",true);
		return (List<GeocodedAddress>)q.getResultList();
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<GeocodedAddress> normalize(String address) {
		Query q = entityManager.createNamedQuery("normalize").setParameter("addressString", address);
		q.setHint("org.hibernate.readOnly",true);
		return (List<GeocodedAddress>)q.getResultList();
	}
}
